Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: expose writeAll() and writeAllSync() #2298

Merged
merged 1 commit into from Jul 23, 2019

Conversation

kevinkassimo
Copy link
Contributor

Symmetric with readAll() and readAllSync(). Also used in xeval.
Also correct usage in writeFile()/writeFileSync().

@piscisaureus
Copy link
Member

IMO write() should write everything, otherwise it is just too surprising. Doesn't it do that currently?
For really specialistic use cases writing "not all" could be appropriate, but that should be very obvious from the name of the function (e.g. writePartial).

@kevinkassimo
Copy link
Contributor Author

kevinkassimo commented May 7, 2019

@piscisaureus Not really. For example, write on a Conn have the following layers of implications (assuming Unix only):
ConnImpl.write ->
tokio_write::write ->
<Resource as AsyncWrite>::poll_write ->
tokio::net::TcpStream::poll_write ->
tokio::net::TcpStream::write ->
PollEvented<mio::net::TcpStream>::write ->
mio::net::TcpStream::write ->
sys::TcpStream::write ->
std::net::TcpStream::write ->
std::sys_common::net::TcpStream::write ->
libc::send

As it eventually goes to send (2) and none of the above step does a write-all attempt, it is possible to write and return partially if something like signal interrupts happens when we have already written some data (from manpages on macOS, EINTR only triggers on no data written yet:)

[EINTR]            A signal interrupts the system call before any data is transmitted.

Symmetric with `readAll()` and `readAllSync()`. Also used in `xeval`.
Also correct usage in `writeFile()`/`writeFileSync()`.
@ry
Copy link
Member

ry commented Jul 23, 2019

I've rebased on current master.

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - sorry for the delay

@ry ry merged commit e49d1e1 into denoland:master Jul 23, 2019
@kevinkassimo kevinkassimo deleted the buf/writeAll branch December 27, 2019 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants